import 'package:flutter_app_demo/constants/constants.dart';
import 'package:flutter_app_demo/utils/NetUtils.dart';

const code = "MCEJQG";
const access_token = "06c6902a-c4e4-443e-b6f8-0fa1292ae792";
const refresh_token = "9d87add9-7d04-4bc5-8e70-104e4d29b120";
const id = 5170983;

main() {
  //testOauth2Authorize();
  //testoauth2_token();
  //test_openapi_user();
  //test_user_information();
  //test_my_information();

  //test_news_list();
  //test_news_detail();
  
  //test_post_list();
  //test_post_pub();
  //test_post_detail();

  //test_tweet_list();
  //test_tweet_detail();

  test_project_detail();
  test_project_tag_list();
  test_project_catalog_list();
  test_project_list();


}

void test_project_list() {
  Map<String, dynamic> params = {
    "access_token": access_token,
    "type": "recommend",
    "dataType": "json",
  };
  NetUtils.get(AppUrls.PROJECT_LIST, params);
}

void test_project_catalog_list() {
}


void test_project_detail() {
  Map<String, dynamic> params = {
    "access_token": access_token,
    "dataType": "json",
  };
  NetUtils.get(AppUrls.PROJECT_DETAIL, params);
}


void test_project_tag_list() {

}


void test_tweet_detail() {
  Map<String, dynamic> params = {
    "access_token": access_token,
    "id": 23342793,
    "dataType": "json",
  };
  NetUtils.get(AppUrls.TWEET_DETAIL, params);
}

void test_tweet_list() {

  Map<String, dynamic> params = {
    "access_token": access_token,
    "pageSize": 10,
    "page": 1,
    "dataType": "json",
  };
  NetUtils.get(AppUrls.TWEET_LIST, params);
}

void test_post_detail() {
  Map<String, dynamic> params = {
    "access_token": access_token,
    "id": 2281243,
    "dataType": "json",
  };
  NetUtils.get(AppUrls.POST_DETAIL, params);
}

void test_post_pub() {
  // Map<String, dynamic> params = {
  //   "access_token": access_token,
  //   "dataType": "json",
  // };
  // NetUtils.get(AppUrls.POST_LIST, params);
}

void test_post_list() {
  Map<String, dynamic> params = {
    "access_token": access_token,
    "dataType": "json",
  };
  NetUtils.get(AppUrls.POST_LIST, params);
}

void test_news_list() {
  Map<String, dynamic> params = {
    "access_token": access_token,
    "catalog": 1,
    "page": 1,
    "pageSize": 10,
    "dataType": "json",
  };
  NetUtils.get(AppUrls.NEWS_LIST, params);
  //{
  //   "newslist": [
  //     {
  //       "author": "Alias_Travis",
  //       "id": 146738,
  //       "title": "Red Panda Dev C++ —— C/C++ 集成开发环境",
  //       "type": 1,
  //       "authorid": 4937141,
  //       "pubDate": "2021-06-20 08:03:48",
  //       "object": 51692,
  //       "commentCount": 0
  //     },
  //     {
  //       "author": "Alias_Travis",
  //       "id": 146737,
  //       "title": "Gitee 推荐 | V8 引擎基础上的应用服务器开发框架 FibJS",
  //       "type": 0,
  //       "authorid": 4937141,
  //       "pubDate": "2021-06-20 08:01:28",
  //       "url": "https://gitee.com/fibjs/fibjs",
  //       "object": 0,
  //       "commentCount": 0
  //     },
  //     {
  //       "author": "Alias_Travis",
  //       "id": 146736,
  //       "title": "每日一博 | Vue 3 的组合 API 如何请求数据？",
  //       "type": 3,
  //       "authorid": 4937141,
  //       "pubDate": "2021-06-20 08:00:09",
  //       "commentCount": 1,
  //       "object": 4681857
  //     },
  //     {
  //       "author": "白开水不加糖",
  //       "id": 146734,
  //       "title": "HanLP 1.8.2 发布，常规维护与修复",
  //       "type": 4,
  //       "authorid": 4252687,
  //       "pubDate": "2021-06-20 07:52:04",
  //       "commentCount": 0
  //     },
  //     {
  //       "author": "白开水不加糖",
  //       "id": 146733,
  //       "title": "SQLite 3.36.0 发布，最常用的数据库引擎",
  //       "type": 4,
  //       "authorid": 4252687,
  //       "pubDate": "2021-06-20 07:42:47",
  //       "commentCount": 0
  //     },
  //     {
  //       "author": "A阿福A",
  //       "id": 146732,
  //       "title": "pgAdmin 4 v5.4 发布",
  //       "type": 4,
  //       "authorid": 592434,
  //       "pubDate": "2021-06-20 07:42:22",
  //       "commentCount": 0
  //     },
  //     {
  //       "author": "白开水不加糖",
  //       "id": 146731,
  //       "title": "WinSCP 5.19.0 发布，Windows 图形化 SFTP 客户端",
  //       "type": 4,
  //       "authorid": 4252687,
  //       "pubDate": "2021-06-20 07:34:12",
  //       "commentCount": 0
  //     },
  //     {
  //       "author": "Alias_Travis",
  //       "id": 146730,
  //       "title": "Tailwind CSS 2.2 发布，快速构建 UI 的 CSS 框架",
  //       "type": 4,
  //       "authorid": 4937141,
  //       "pubDate": "2021-06-20 07:31:08",
  //       "commentCount": 0
  //     },
  //     {
  //       "author": "A阿福A",
  //       "id": 146729,
  //       "title": "Psycopg 2.9 发布",
  //       "type": 4,
  //       "authorid": 592434,
  //       "pubDate": "2021-06-20 07:21:20",
  //       "commentCount": 0
  //     },
  //     {
  //       "author": "Alias_Travis",
  //       "id": 146728,
  //       "title": "uBlock 1.36.0 发布，浏览器高效过滤插件",
  //       "type": 4,
  //       "authorid": 4937141,
  //       "pubDate": "2021-06-20 07:16:37",
  //       "commentCount": 0
  //     }
  //   ],
  //   "notice": {
  //     "referCount": 0,
  //     "replyCount": 0,
  //     "msgCount": 0,
  //     "fansCount": 0
  //   }
  // }
}

void test_news_detail() {
  Map<String, dynamic> params = {
    "access_token": access_token,
    "id": 146737,
    "dataType": "json",
  };
  NetUtils.get(AppUrls.NEWS_DETAIL, params);
  //{
  //   "author": "Alias_Travis",
  //   "id": 146737,
  //   "authorid": 4937141,
  //   "title": "Gitee 推荐 | V8 引擎基础上的应用服务器开发框架 FibJS",
  //   "body": "<style type='text/css'>pre {white-space:pre-wrap;word-wrap:break-word;}</style><p>FibJS 是一个建立在 Google v8 Javascript 引擎基础上的应用服务器开发框架，不同于 node.js，FibJS 采用 fiber 解决 v8 引擎的多路复用，并通过大量 c++ 组件，将重负荷运算委托给后台线程，释放 v8 线程，争取更大的并发时间</p>",
  //   "pubDate": "2021-06-20 08:01:28",
  //   "favorite": 0,
  //   "url": "https://gitee.com/fibjs/fibjs",
  //   "relativies": [
  //     {
  //       "title": "V8 JavaScript 引擎 6.9 发布：继续对内存进行优化",
  //       "url": "https://www.oschina.net/news/98755/v8-6-9-released"
  //     },
  //     {
  //       "title": "腾讯云容器服务平台增加对码云 Gitee 的支持",
  //       "url": "https://www.oschina.net/news/98262/tencent-hub-support-gitee"
  //     },
  //     {
  //       "title": "Node.js 10.7.0 发布，基于 V8 的 JavaScript 运行时",
  //       "url": "https://www.oschina.net/news/98137/nodejs-10-7-0-released"
  //     },
  //     {
  //       "title": "码云 Gitee 微信服务号支持账号登陆通知啦~",
  //       "url": "https://www.oschina.net/news/97654/gitee-wechat-login-notification"
  //     },
  //     {
  //       "title": "协作翻译 | 深入解读 V8 引擎的「并发标记」技术",
  //       "url": "https://www.oschina.net/translate/v8-javascript-engine"
  //     },
  //     {
  //       "title": "V8 JavaScript 引擎 6.8 发布，改进内存占用",
  //       "url": "https://www.oschina.net/news/97304/v8-68-released"
  //     },
  //     {
  //       "title": "Node.js 10.5.0 发布，基于 V8 的 JavaScript 运行时",
  //       "url": "https://www.oschina.net/news/97262/nodejs-10-5-0-released"
  //     },
  //     {
  //       "title": "Node v10.4.0 发布，升级 V8 引擎至 6.7.288.43 版本",
  //       "url": "https://www.oschina.net/news/96821/node-10-4-0-released"
  //     },
  //     {
  //       "title": "Node.js 10.3.0 发布，基于 V8 的 JavaScript 运行时",
  //       "url": "https://www.oschina.net/news/96565/nodejs-10-3-0-released"
  //     },
  //     {
  //       "title": "码云（Gitee）团队如何使用码云完成开发？",
  //       "url": "https://blog.gitee.com/2018/05/27/gitee_way/"
  //     }
  //   ],
  //   "commentCount": 0,
  //   "notice": {
  //     "referCount": 0,
  //     "replyCount": 0,
  //     "msgCount": 0,
  //     "fansCount": 0
  //   }
  // }
}

void test_my_information() {
  Map<String, dynamic> params = {
    "access_token": access_token,
    "dataType": "json",
  };
  NetUtils.get(AppUrls.MY_INFORMATION, params);
  //{
  //   "gender": 0,
  //   "joinTime": "2021-06-17 08:12:36",
  //   "city": "深圳",
  //   "fansCount": 0,
  //   "portrait": "https://oscimg.oschina.net/oscnet/up-6554baac39427a6d875cb12b2c0fe627.jpg!/both/50x50",
  //   "expertise": [],
  //   "platforms": [],
  //   "uid": 5170983,
  //   "lastLoginTime": "2021-06-20 07:44:15",
  //   "province": "广东",
  //   "name": "osc_64142869",
  //   "followersCount": 0,
  //   "favoriteCount": 0,
  //   "notice": {
  //     "referCount": 0,
  //     "replyCount": 0,
  //     "msgCount": 0,
  //     "fansCount": 0
  //   }
  // }
}

void test_user_information() {
  Map<String, dynamic> params = {
    "access_token": access_token,
    "user": id,
    "friend": 2281883,
    "dataType": "json",
  };
  NetUtils.get(AppUrls.USER_INFORMATION, params);
  //{
  //   "gender": 0,
  //   "joinTime": "2021-06-17 08:12:36",
  //   "city": "深圳",
  //   "ident": null,
  //   "portrait": "https://oscimg.oschina.net/oscnet/up-6554baac39427a6d875cb12b2c0fe627.jpg!/both/50x50",
  //   "expertise": [],
  //   "platforms": [],
  //   "relation": 3,
  //   "uid": 5170983,
  //   "lastLoginTime": "2021-06-20 07:44:15",
  //   "province": "广东",
  //   "name": "osc_64142869",
  //   "notice": {
  //     "referCount": 0,
  //     "replyCount": 0,
  //     "msgCount": 0,
  //     "fansCount": 0
  //   }
  // }
}


void test_openapi_user() {

  Map<String, dynamic> params = {
    "access_token": access_token,
    "dataType": "json",
  };
  NetUtils.get(AppUrls.OPENAPI_USER, params);
  //{
  //   "gender": "female",
  //   "name": "osc_64142869",
  //   "location": "广东 深圳",
  //   "id": 5170983,
  //   "avatar": "https://oscimg.oschina.net/oscnet/up-6554baac39427a6d875cb12b2c0fe627.jpg!/both/50x50",
  //   "email": "31e812d7-efa5-4a21-beb5-4aecaa0d4b35",
  //   "url": "https://my.oschina.net/u/5170983"
  // }
}

void testoauth2_token() {
  Map<String, dynamic> params = {
    "client_id": AppParams.CLIENT_ID,
    "client_secret": AppParams.CLIENT_SECRET,
    "redirect_uri": AppParams.REDIRECT_URI,
    "grant_type": "authorization_code",
    "code": "$code",
    "dataType": "json",
  };

  print("params $params");

  NetUtils.get(AppUrls.OAUTH2_TOKEN, params).then((data) {
    //{
    //   "access_token": "06c6902a-c4e4-443e-b6f8-0fa1292ae792",
    //   "refresh_token": "9d87add9-7d04-4bc5-8e70-104e4d29b120",
    //   "uid": 5170983,
    //   "token_type": "bearer",
    //   "expires_in": 546476
    // }
  });
}

//https://blog.csdn.net/yuzhangzhen?code=IW14Py&state=
void testOauth2Authorize() {
  NetUtils.get(AppUrls.OAUTH2_AUTHORIZE, {
    "client_id": AppParams.CLIENT_ID,
    "client_secret": AppParams.CLIENT_SECRET,
    "redirect_uri": AppParams.REDIRECT_URI,
    "response_type": "code",
  });
}
